fix(server): fall back to plain gh auth status on CLIs without --json#3943
fix(server): fall back to plain gh auth status on CLIs without --json#3943webdevtodayjason wants to merge 2 commits into
gh auth status on CLIs without --json#3943Conversation
GitHub auth discovery runs `gh auth status --json hosts`. CLIs older than 2.81 do not support the flag, exit non-zero with `unknown flag: --json`, and are reported as unauthenticated no matter how many times the user runs `gh auth login` — the message points at the login, but the cause is the CLI version. Add an optional `authFallbackArgs` to the CLI discovery spec, retried only when the primary probe exits non-zero without resolving an account, and give the GitHub spec a `gh auth status` fallback whose human-readable output is parsed (both the current `account <login>` and the older `as <login>` phrasings). Behavior is unchanged for providers that do not set the new field, and for any CLI where the primary probe already succeeds. Fixes pingdotgg#3806
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Want fixes drafted automatically? Bugbot Autofix can create code changes for findings. A team admin can enable Autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit b4a5abc. Configure here.
ApprovabilityVerdict: Needs human review This PR introduces new text parsing logic with multiple regex patterns and modifies the source control discovery flow with conditional fallback behavior. While the backward compatibility intent is clear and tests are comprehensive, the new parsing capability and discovery flow changes warrant human review. You can customize Macroscope's approvability policy. Learn more. |
Address review feedback: the auth fallback previously ran whenever the primary probe exited non-zero and was not authenticated, which includes a modern CLI that is simply signed out. That ran the fallback needlessly and could replace the primary's specific error with a generic sign-in hint. Gate the fallback on `looksLikeUnsupportedInvocation` — a non-zero exit whose output matches the Cobra `unknown flag/command` signal — so it fires only when the CLI is too old for the primary args. A genuine sign-out keeps its detail and skips the fallback. Adds a regression test. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FLywDkpwfSx6Q7DxgxYBME

Fixes #3806.
Problem
GitHub auth discovery probes with
gh auth status --json hosts. The--jsonflag landed in gh 2.81; older CLIs exit non-zero withunknown flag: --json, soparseGitHubAuthStatussees no JSON, and the probe reports Not authenticated — with a detail line telling the user to sign in. Users then rungh auth loginrepeatedly, which never helps, because the login is fine and the CLI version is the problem.Reproduced on Linux with
gh 2.45.0(Ubuntu's package), fully logged in:T3 reported:
auth: { status: "unauthenticated", detail: "unknown flag: --json" }.Fix
authFallbackArgstoSourceControlCliDiscoverySpec. It is retried only when the primary auth probe exits non-zero and did not resolve an account, so there is no extra process spawn on the happy path, and no behavior change for providers that do not set it.authFallbackArgs: ["auth", "status"].parseGitHubAuthStatusText), handling both the currentLogged in to <host> account <login>and the olderLogged in to <host> as <login>phrasings, plusActive account:and failed-login lines. This mirrors the existing text parsing ingitLabAuthStatus.ts.Verification
Built the server from this branch and ran it against a
ghstub that rejects--jsonand prints the 2.45.0 text output:auth.statusunauthenticatedauthenticatedauth.accountoctocatauth.detailunknown flag: --jsonvp test run apps/server/src/sourceControl/— 93 passed (12 files), including 4 new tests: three parser cases (current phrasing, legacyas <login>phrasing, failed login stays unauthenticated) and one discovery-level test asserting the fallback runs and recovers the account when--jsonis rejected.vp run --filter t3 typecheck— clean.vp check— 0 errors.Notes
Scoped to GitHub deliberately. GitLab/Azure/Bitbucket specs are untouched; the new spec field is opt-in, so the same mechanism is available if another CLI ever needs it.
Note
Low Risk
Scoped to opt-in GitHub auth discovery and parsing; happy path unchanged and genuine sign-out messages are preserved without extra CLI calls.
Overview
Fixes false unauthenticated GitHub discovery when
ghis older than 2.81 and rejectsauth status --json hostswith errors likeunknown flag: --json.Discovery gains optional
authFallbackArgson CLI specs andlooksLikeUnsupportedInvocationso a second probe runs only when the primary command fails with an unsupported-flag/command pattern—not when the user is genuinely signed out. GitHub setsauthFallbackArgs: ["auth", "status"].Auth parsing adds
parseGitHubAuthStatusTextfor human-readablegh auth statusoutput (currentaccountphrasing, legacyas <login>, active/failed lines).parseGitHubAuthuses JSON when it parses, otherwise plain text from combined stdout/stderr.Tests cover the text parser, end-to-end fallback recovery, and the case where a modern CLI reports sign-out without triggering fallback.
Reviewed by Cursor Bugbot for commit 2a2e502. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Fall back to plain
gh auth statuswhen GitHub CLI does not support--jsonauthFallbackArgsto the CLI discovery spec andparseGitHubAuthStatusTextto parse human-readablegh auth statusoutput from older GitHub CLI versions.gh auth status --json hosts) exits non-zero with an "unknown flag" error,SourceControlProviderDiscoveryretries using the plaingh auth statuscommand.gitHubAuthStatus.tshandles both current (account) and legacy (as) phrasing in plain-text output.Macroscope summarized 2a2e502.